﻿/**
 * ...
 * @author sminutoli
 */
import com.dmotiko.prune.*
import com.dmotiko.util.StringUtils;
 
class NewsLoader {

	public static function run(src, target){
		
		var xml:XML = new XML();
		xml.ignoreWhite = true;
		xml.load(src);
				
		xml.onLoad = function(){
			var news:Array = this.firstChild.childNodes;
			
			var newsData:Array = new Array();
			var oNew:Object;
			for (var i:Number = 0; i < news.length; i++) {
				oNew = new Object();
				oNew.date = news[i].attributes.date;
				var aDate:Array = new String( oNew.date ).split("-");
				var initDate:Date = new Date(aDate[0], Number(aDate[1])-1, aDate[2]);
				var sDate:String = aDate[2] + "-" + aDate[1] + "-" + aDate[0].substring(2);
				oNew.date = sDate;
				oNew.href = news[i].attributes.href;
				oNew.doc = news[i].attributes.doc;
				oNew.home = news[i].attributes.home == "true";
												
				oNew.expires = news[i].attributes.expires;
				oNew.src = news[i].attributes.src;
				oNew.title = news[i].attributes.title;
				oNew.title = StringUtils.replace(oNew.title, "&quot;", '"');
				oNew.content = news[i].firstChild.firstChild.toString();
				oNew.content = StringUtils.replace(oNew.content, String.fromCharCode(10), "");
				oNew.content = StringUtils.replace(oNew.content, "&quot;", '"');
				
				newsData.push(oNew);
				
			}
			target.setData(newsData);
		}
		
	}

}